//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类.demo_1472;

import java.util.ArrayList;
import java.util.List;

public class BrowserHistory {
    List<String> urls = new ArrayList();
    int index = 0;

    public BrowserHistory(String homepage) {
        this.urls.add(homepage);
    }

    public void visit(String url) {
        ++this.index;
        this.urls.subList(this.index, this.urls.size()).clear();
        this.urls.add(url);
    }

    public String back(int steps) {
        this.index -= steps;
        if (this.index < 0) {
            this.index = 0;
        }

        if (this.index >= this.urls.size()) {
            this.index = this.urls.size() - 1;
        }

        return (String)this.urls.get(this.index);
    }

    public String forward(int steps) {
        this.index += steps;
        if (this.index < 0) {
            this.index = 0;
        }

        if (this.index >= this.urls.size()) {
            this.index = this.urls.size() - 1;
        }

        return (String)this.urls.get(this.index);
    }
}
